<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Growfield Performance Tests</title>
    <script type="text/javascript" src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js'></script>
    <script type="text/javascript" src='jquery.easing.js'></script>
    <script type="text/javascript" src='jquery.mousewheel.js'></script>
    <script type="text/javascript" src='@DESTFILE@'></script>
    <script type="text/javascript">
        var test = function(params){
            if(params.setUp){
                params.setUp();
            }
            try{
                var start = new Date().getTime();
                params.test();
                var end = new Date().getTime();

                logResult("Elapsed time for " + params.name + " : " + (end - start) + " milliseconds");
            }
            catch(e){
                logResult("Error: " + e);
            }
            finally {
                if(params.tearDown){
                    params.tearDown();
                }
            }
        }

        function logResult(msg){
            $("#results").append(msg).append("<br>");
        }

        var stressLevel = 1000;

        function baseTest(){
            test({
                test: function(){
                    var container = $("#container");
                    var element = document.createElement("textarea");
                    element.innerHtml = "woo hoo";
                    for(var i = 0; i < stressLevel; i++){
                        container.append(element);
                        container.find("textarea");
                        container.empty();
                    }
                },
                tearDown: function(){
                    $("#container").empty();
                },
                name: "Base 1: Create 1 at a time " + stressLevel + " times"
            });

            test({
                setUp: function(){
                    var container = $("#container");
                    var element = document.createElement("textarea");
                    element.innerHtml = "woo hoo";
                    for(var i = 0; i < stressLevel; i++){
                        container.append(element);
                    }
                },
                test: function(){
                    $("#container").find("textarea");
                },
                tearDown: function(){
                    $("#container").empty();
                },
                name: "Base 2: Create " + stressLevel + " and test selector"
            });
        }

        function testInit(){
            test({
                test: function(){
                    var container = $("#container");
                    var element = document.createElement("textarea");
                    element.innerHtml = "woo hoo";
                    for(var i = 0; i < stressLevel; i++){
                        container.append(element);
                        container.find("textarea").growfield();
                        container.empty();
                    }
                },
                tearDown: function(){
                    $("#container").empty();
                },
                name: "Actual 1: Create 1 at a time " + stressLevel + " times and apply growfield individually"
            });

            test({
                setUp: function(){
                    var container = $("#container");
                    var element = document.createElement("textarea");
                    element.innerHtml = "woo hoo";
                    for(var i = 0; i < stressLevel; i++){
                        container.append(element);
                    }
                },
                test: function(){
                    $("#container").find("textarea").growfield();
                },
                tearDown: function(){
                    $("#container").empty();
                },
                name: "Actual 2: Create " + stressLevel + " and apply growfield to all"
            });
        }

        $(document).ready(function(){
            $("#runTests").click(function(){
                baseTest();
                testInit();
            });
        });
    </script>
</head>
<body>
<input id="runTests" type="button" value="Run Tests!">
<div id="container">
</div>
<div id="results">

</div>
</body>
</html>